package com.zerui.manager.access.auth.task.domain;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class AuthTaskDetail {

    private Long id;
    /**
     * 权限组
     */
    private Long accessAuthId;
    /**
     * 任务ID
     */
    private Long taskId;
    /**
     * 设备ID
     */
    private Long deviceId;
    /**
     * 设备源  1：IoT 2：ICC
     */
    private Integer deviceFrom;
    /**
     * 人员ID
     */
    private Long personnelId;
    /**
     * 操作（0 - 添加；1 - 删除）
     */
    private Integer operate;
    /**
     * 任务下发状态（0 - 未执行；1 - 执行中；2 - 执行失败; 3 - 执行成功）
     */
    private Integer syncStatus;
    /**
     * 请求ID
     */
    private String requestId;
    /**
     * 返回结果
     */
    private String responseData;
    /**
     * 重试次数
     */
    private Integer retryTimes;

    public static AuthTaskDetail of(Long accessAuthId, Long deviceId, Long personnelId, Integer operate) {
        AuthTaskDetail detail = new AuthTaskDetail();
        detail.accessAuthId = accessAuthId;
        detail.deviceId = deviceId;
        detail.personnelId = personnelId;
        detail.operate = operate;
        detail.syncStatus = 0;
        detail.retryTimes = 0;
        return detail;
    }

    public AuthTaskDetail failure(String responseData) {
        this.responseData = responseData;
        this.syncStatus = 0;
        this.retryTimes++;
        return this;
    }

    public AuthTaskDetail success() {
        this.syncStatus = 3;
        return this;
    }
}
